package com.service.impl;

import com.dao.InformationDao;
import com.entity.Information;
import com.common.utils.Page;
import com.service.InformationService;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * 用户Service接口实现类
 */
@Service("informationService")
@Transactional
public class InformationServiceImpl implements InformationService {
	// 注入InformationDao
	@Autowired
	private InformationDao informationDao;
	
	public Page<Information> findInformationList(Integer page, Integer rows,String title) {

			// 创建对象
	         Information information = new Information();
	 		if(StringUtils.isNotBlank(title)){
				information.setTitle(title);
			}
			// 当前页
			information.setStart((page-1) * rows) ;
			// 每页数
			information.setRows(rows);
			// 查询列表
			List<Information> informations = 
	                            informationDao.selectInformationList(information);
			// 查询列表总记录数
			Integer count = informationDao.selectInformationListCount(information);
			Page<Information> result = new Page<>();
			result.setPage(page);
			result.setRows(informations);
			result.setSize(rows);
			result.setTotal(count);
			return result;
	}

	@Override
	public int createInformation(Information information) {
		// TODO Auto-generated method stub
		return informationDao.createInformation(information);
	}

	@Override
	public int deleteInformation(Integer id) {
		// TODO Auto-generated method stub
		return informationDao.deleteInformation(id);
	}

	@Override
	public Information getInformationById(Integer id) {
		// TODO Auto-generated method stub
		return informationDao.getInformationById(id);
	}

	@Override
	public int updateInformation(Information information) {
		// TODO Auto-generated method stub
		return informationDao.updateInformation(information);
	}
}
